home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
clipper
/
nfsrc21.zip
/
METAPH.PRG
< prev
next >
Wrap
Text File
|
1991-08-15
|
15KB
|
394 lines
/*
* File......: METAPH.PRG
* Author....: Dave Adams
* Date......: $Date: 15 Aug 1991 23:04:00 $
* Revision..: $Revision: 1.2 $
* Log file..: $Logfile: E:/nanfor/src/metaph.prv $
*
* This is an original work by Dave Adams and is placed in the
* public domain.
*
* Modification history:
* ---------------------
*
* $Log: E:/nanfor/src/metaph.prv $
*
* Rev 1.2 15 Aug 1991 23:04:00 GLENN
* Forest Belt proofread/edited/cleaned up doc
*
* Rev 1.1 14 Jun 1991 19:52:20 GLENN
* Minor edit to file header
*
* Rev 1.0 01 Apr 1991 01:01:44 GLENN
* Nanforum Toolkit
*
*/
/* $DOC$
* $FUNCNAME$
* FT_METAPH()
* $CATEGORY$
* String
* $ONELINER$
* Convert a character string to MetaPhone format
* $SYNTAX$
* FT_METAPH( <cName> [, <nSize> ] ) -> cMetaPhone
* $ARGUMENTS$
* <cName> is the character string to convert
* <nSize> is the length of the character string to be returned.
* If not specified the default length is 4 bytes.
* $RETURNS$
* A phonetically spelled character string
* $DESCRIPTION$
* This function is a character function use to index and search for
* sound-alike or phonetic matches. It is an alternative to
* the SOUNDEX() function, and addresses some basic pronunciation
* rules, by looking at surrounding letters to determine how parts of
* the string are pronounced. FT_METAPH() will group sound-alikes
* together, and forgive shortcomings in spelling ability.
* $EXAMPLES$
* USE Persons
* INDEX ON FT_METAPH( LastName ) TO LastName
* SEEK FT_METAPH( "Philmore" )
* ? FOUND(), LastName // Result: .T. Philmore
* SEEK FT_METAPH( "Fillmore" )
* ? FOUND(), LastName // Result: .T. Philmore
* $END$
*/
/*
* File Contents
*
* FT_METAPH() Calculates the metaphone of a name
* _ftMakeAlpha() Removes non-alpha characters from a string
* _ftConvVowel() Converts all vowels to the letter 'v'
*
*
* Commentary
*
* The concepts for this algoritm were adapted from an article in the
* Computer Language Magazine (Dec.90, Vol.7, No.12) written by
* Lawrence B.F. Phillips.
*
* The STRTRAN function was selected to calculate the MetaPhone, to
* allow the algoritm to be fine-tuned in an easy manner, as there are
* always exceptions to any phonetic pronunciation in not only English,
* but many other languages as well.
*
* What is a metaphone?
* Basically it takes a character string, removes the vowels, and equates
* letters (or groups of letters) to other consonent sounds. The vowels
* are not removed until near the end, as they play an important part
* in determining how some consonents sound in different surroundings.
*
* The consonant sounds are: B, F, H, J, K, L, M, N, P, R, S, T, W, X, Y, 0
* Vowels are only included if they are at the beginning.
* Here are the transformations. The order of evaluation is important
* as characters may meet more than one transformation conditions.
* ( note: v = vowel )
*
* B --> B unless at end of a word after 'm' as in dumb.
* C --> X (sh) CIA, TCH, CH, ISCH, CC
* S SCI, SCE, SCY, CI, CE, CY
* K otherwise ( including CK )
* D --> J DGE, DGY, DGI
* T otherwise
* F --> F
* G --> K GHv, vGHT
* W vGH
* J DGE, DGY, DGI, GI, GE, GY
* N GN
* K otherwise
* H --> H vHv
* otherwise silent
* J --> J
* K --> K
* L --> L
* M --> M
* N --> N
* P --> F PH
* P otherwise
* Q --> K
* R --> R
* S --> X (sh) SH, SIO, SIA, ISCH
* S otherwise
* T --> X (sh) TIA, TIO, TCH
* 0 (th) TH
* T otherwise
* V --> F
* W --> W
* X --> KS
* Y --> vY
* Y otherwise
* Z --> S
*
*/
*------------------------------------------------
// Demo of FT_METAPH()
// #define FT_TEST .T.
#IFDEF FT_TEST
FUNCTION MAIN()
LOCAL cJunk := SPACE( 8000 )
LOCAL aNames := {}
LOCAL cName, nElem
SET( _SET_SCOREBOARD, .F. )
SET( _SET_COLOR, "W/B" )
CLS
// Demo will create an array of names and display in 3 columns
// _ftRow() and _ftCol() will calculate the screen co-ordinates
// by evaluating the element number
AADD( aNames, "Adams" )
AADD( aNames, "Addams" )
AADD( aNames, "Atoms" )
AADD( aNames, "Adamson" )
AADD( aNames, "Cajun" )
AADD( aNames, "Cagen" )
AADD( aNames, "Cochy" )
AADD( aNames, "Cocci" )
AADD( aNames, "Smith" )
AADD( aNames, "Smythe" )
AADD( aNames, "Naylor" )
AADD( aNames, "Nailer" )
AADD( aNames, "Holberry" )
AADD( aNames, "Wholebary" )
AADD( aNames, "Jackson" )
AADD( aNames, "Jekksen" )
AADD( aNames, "The Source" )
AADD( aNames, "The Sores" )
AADD( aNames, "Jones" )
AADD( aNames, "Johns" )
AADD( aNames, "Lennon" )
AADD( aNames, "Lenin" )
AADD( aNames, "Fischer" )
AADD( aNames, "Fisher" )
AADD( aNames, "O'Donnell" )
AADD( aNames, "O Donald" )
AADD( aNames, "Pugh" )
AADD( aNames, "Pew" )
AADD( aNames, "Heimendinger" )
AADD( aNames, "Hymendinker" )
AADD( aNames, "Knight" )
AADD( aNames, "Nite" )
AADD( aNames, "Lamb" )
AADD( aNames, "Lamb Chops" )
AADD( aNames, "Stephens" )
AADD( aNames, "Stevens" )
AADD( aNames, "Neilson" )
AADD( aNames, "Nelson" )
AADD( aNames, "Tchaikovski" )
AADD( aNames, "Chikofski" )
AADD( aNames, "Caton" )
AADD( aNames, "Wright" )
AADD( aNames, "Write" )
AADD( aNames, "Right" )
AADD( aNames, "Manual" )
AADD( aNames, "Now" )
AADD( aNames, "Wheatabix" )
AADD( aNames, "Science" )
AADD( aNames, "Cinzano" )
AADD( aNames, "Lucy" )
AADD( aNames, "Reece" )
AADD( aNames, "Righetti" )
AADD( aNames, "Oppermann" )
AADD( aNames, "Bookkeeper" )
AADD( aNames, "McGill" )
AADD( aNames, "Magic" )
AADD( aNames, "McLean" )
AADD( aNames, "McLane" )
AADD( aNames, "Maclean" )
AADD( aNames, "Exxon" )
// display names and metaphones in 3 columns on screen
AEVAL( aNames, ;
{ | cName, nElem | ;
SETPOS( _ftRow( nElem ), _ftCol( nElem ) ), ;
QQOUT( PadR( cName, 18, "." ) + FT_METAPH( cName ) ) ;
} )
SETPOS( 21, 00 )
QUIT
*------------------------------------------------
STATIC FUNCTION _ftRow( nElem ) // Determine which row to print on
RETURN IIF( nElem > 40, nElem - 40, IIF( nElem > 20, nElem - 20, nElem ) )
*------------------------------------------------
STATIC FUNCTION _ftCol( nElem ) // Determine which column to start print
RETURN IIF( nElem > 40, 55, IIF( nElem > 20, 28, 1 ) )
*------------------------------------------------
#endif
// End of Test program
*------------------------------------------------
FUNCTION FT_METAPH ( cName, nSize )
// Calculates the metaphone of a character string
LOCAL cMeta
cName := IIF( cName == NIL, "", cName ) // catch-all
nSize := IIF( nSize == NIL, 4, nSize ) // default size: 4-bytes
// Remove non-alpha characters and make upper case.
// The string is padded with 1 space at the beginning & end.
// Spaces, if present inside the string, are not removed until all
// the prefix/suffix checking has been completed.
cMeta := " " + _ftMakeAlpha( UPPER( ALLTRIM( cName ) ) ) + " "
// prefixes which need special consideration
IF " KN" $ cMeta ; cMeta := STRTRAN( cMeta, " KN" , " N" ) ; ENDIF
IF " GN" $ cMeta ; cMeta := STRTRAN( cMeta, " GN" , " N" ) ; ENDIF
IF " PN" $ cMeta ; cMeta := STRTRAN( cMeta, " PN" , " N"